<template>
  <div class="myInput">
    <div class="label">
      <div class="text">{{ label }}：</div>
      <div v-if="required" class="icon" style="color: red">*</div>
    </div>
    <input
      type="text"
      :value="value"
      :placeholder="placeholder"
      class="input"
      @input="onInput"
    />
  </div>
</template>

<script>
export default {
  props: {
    required: {
      type: Boolean,
      default: false,
    },
    value: {
      default: "",
    },
    placeholder: {
      default: "",
    },
    label: {
      default: "",
    },
  },
  methods: {
    onInput(e) {
      this.$emit("update:value", e.target.value);
    },
  },
};
</script>

<style lang="less" scoped>
.myInput {
  display: flex;
  align-items: center;
  width: 100%;
  height: 100%;
  .input {
    flex-shrink: 1;
    width: 184px;
    height: 30px;
    border-radius: 5px;
    padding: 0 8px;
    box-sizing: border-box;
    color: #333;
    font-size: 14px;
    outline: none;
    border: 1px solid #d7d7d7;
    &::-webkit-input-placeholder {
      color: #808595;
      font-size: 14px;
    }
    &:-moz-placeholder {
      color: #808595;
      font-size: 14px;
    }
    &::-moz-placeholder {
      color: #808595;
      font-size: 14px;
    }
    &:-ms-input-placeholder {
      color: #808595;
      font-size: 14px;
    }
  }
  .label {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    .text {
      width: 100%;
      color: #333;
      font-size: 14px;
      text-align: right;
      white-space: nowrap;
    }
    .icon {
      margin-right: 10px;
    }
  }
}
</style>